package cn.message.service.impl;

import cn.itcast.mapper.accountMapper;
import cn.itcast.pojo.account;
import cn.itcast.pojo.accountExample;
import cn.message.service.IAccountService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 郭智超
 * @create 2020-04-06 9:55
 */
@Service
@Slf4j
public class AccountServiceServiceImpl implements IAccountService {

    @Resource
    private accountMapper accountMapper;

    @Override
    public Map<String, Object> getAllAccount(Map<String,String> map) {
        System.out.println("开始执行getAllAccount方法了");
        accountExample accountExample = new accountExample();
        cn.itcast.pojo.accountExample.Criteria criteria = accountExample.createCriteria();

        //添加查询条件
        //根据账户名称模糊搜索
        if(!map.get("accountName").isEmpty()){
            criteria.andAccountNameLike("%"+map.get("accountName")+"%");
        }

        //根据账户类型搜索
        if(!map.get("accountType").isEmpty()){
            criteria.andAccountTypeidEqualTo(Integer.parseInt(map.get("accountType")));
        }

        //返回符合查询条件的总记录数
        Integer count = accountMapper.countByExample(accountExample);

        Integer page = Integer.parseInt(map.get("page"));
        Integer limit = Integer.parseInt(map.get("limit"));
        //分页
        PageHelper.startPage(page, limit);

        //查询所有符合条件的商品分类的信息
        List<account> accountList = accountMapper.selectByExample(accountExample);


        Map<String,Object> resultMap = new HashMap<String, Object>();
        resultMap.put("count",count);
        resultMap.put("accountList",accountList);

        return resultMap;
    }
}
